// pages/resources/resources.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    record: [], //资源列表
    total: 0, //总页数
    current: 1, //当前页数
    page: 1,
    pageData: 0,
    clockresult:[],
    title:''
  },

  //------------------------高级查询--------------------------------
  houduanTab_input(e){
    // console.log(e.detail.value);
    this.setData({
      title:e.detail.value
    });
  },
  mySelect(){
    this.resourcesList();
  },
  //----------------------------清空搜索框---------------------------------
  empty(){
    this.setData({
      inputData:'',
      title:''
    })
  },

  //-------------------------获取资源列表----------------------------
  resourcesList() {
    var that = this;
    wx.request({
      url: app.globalData.myUrl + '/resources/list',
      data: {
        title:that.data.title,
        current: that.data.current,
        pageSize: 8,
      },
      method: 'GET',
      success: (res) => {
        // console.log(res.data);
        if (res.data.success) {
          that.setData({
            record: res.data.msg.msg,
            total: res.data.msg.total,
            current: res.data.msg.current
          });
          // console.log(res.data.msg);
        }
      },
      fail: (res) => {},
    })
  },

  //-----------------------获取指定资源详情--------------------------
  getResource(e) {
    wx.navigateTo({
      url: '/pages/resourcesDetails/resourcesDetails?id=' + e.currentTarget.id
    })
  },


  //---------------------------上一页--------------------------------
  upPage(){
    var that = this;
    if (that.data.current <= 1) {
      that.errShowToast('已经是第一页了');
      return;
    }
    that.data.current --; 
    that.setData({
      current: that.data.current
    });
    this.resourcesList();
  },

  //---------------------------下一页--------------------------------
  nextPage(){
    var that = this;
    if (that.data.current >= that.data.total) {
      that.errShowToast('已经是最后一页了');
      return;
    }
    that.data.current ++; 
    that.setData({
      current: that.data.current
    });
    // console.log(that.data.current);
    this.resourcesList();
  },

  //---------------------------函数封装------------------------------
  errShowToast: function (toastText) {
    wx.showToast({
      title: toastText,
      image: '/images/password.png',
      duration: 2000
    });
  },
  sucShowToast: function (toastText) {
    wx.showToast({
      title: toastText,
      duration: 2000
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.resourcesList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.resourcesList();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  /**
   * 分享到朋友圈
   */
  // onShareTimeline: function() {
  //   return {
  //     title: '一个小demo',
  //     imageUrl: "https://www.kongbai121.xyz/drawing-bed/2023-01/59e40761-c197-4b17-be36-bfbd1f2cfa1c.jpg"
  //   }
  // },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '一个小demo',
      path: '/pages/loading/loading',
      imageUrl: "https://www.kongbai121.xyz/drawing-bed/2023-01/59e40761-c197-4b17-be36-bfbd1f2cfa1c.jpg"
    }
  }
})